package com.zbl.singleDemo.core;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;

import java.io.IOException;

/**
 * @author zbl1997
 * @date 2022/12/19
 * @desc
 */
public class ResourceDemo {
    public static void main(String[] args) throws IOException {
        DefaultResourceLoader defaultResourceLoader = new DefaultResourceLoader();
        Resource resource = defaultResourceLoader.getResource("classpath:images/神里绫华.jpeg");
        System.out.println(resource.exists());
        System.out.println(resource.getFilename());
        System.out.println(resource.getDescription());
        System.out.println("-------------------");

        ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext();
        Resource[] resources = classPathXmlApplicationContext.getResources("classpath*:**/神里绫华.jpeg");
        for (Resource res : resources) {
            System.out.println(res.exists());
            System.out.println(res.getFilename());
        }
    }
    // java包和resources包编译后存放的位置： classpath:
    // 一个匹配项： classpath:images/神里绫华.jpeg
    // 多个匹配项： classpath*:images/神里绫华.jpeg
    // 任意目录下的多个匹配项： classpath*:**/神里绫华.jpeg
}
